<?
require_once("ArticlePrototype.php");
require_once '../tables/ArticlesTable.php';


class ArticlesFactory {

    var $articles;
    var $table;
   
    function ArticlesFactory ( &$dbConn ) {
        // Pull the articles from the database
        $table = "articles";
		//$auto_create = 'safe';
		$this->table =& new ArticlesTable($dbConn, $table, $auto_create);
		$this->table->fetchmode = DB_FETCHMODE_ASSOC;

		$rows = $this->table->select('list');
		//print_r($rows);
		
		//$sql="SELECT * FROM articles";
        //$result = $dbConn->query($sql);
		$this->articles[]=current($rows);
		print_r($row);
        while ( $row = next($rows) ) {
		    print_r($row);
            $this->articles[]=$row;
        }
    }
 
    // Factory method creates new instances of Article
    public function & getArticle () {
        $row=each($this->articles);
		//print_r($row['value']);
        return new ArticlePrototype($row['value']);
    }
	
	public function addArticle($cols_vals){
		$id = $this->table->nextID();
		$result = $this->table->insert($cols_vals);
		if ($this_table->error) {
    		echo "Failure!  Try again.";
    		print_r($this->table->error);
		}
	}
	
	public function getTable(){
		return $this->table;
	}
	
}


?>